package com.helloworld.demo;

import com.sun.crypto.provider.DESKeyFactory;
import sun.misc.Launcher;

import java.net.URL;


public class JDKClassLoaderTest {

    public static void main(String[] args) {
        System.out.println(String.class.getClassLoader());         //rt.jar

        System.out.println(DESKeyFactory.class.getClassLoader());  //ext

        System.out.println(JDKClassLoaderTest.class.getClassLoader()); //自定义


        System.out.println();

        ClassLoader appClassLoader = ClassLoader.getSystemClassLoader();
        ClassLoader extClassLoader = appClassLoader.getParent();
        ClassLoader bootstrapClassLoader = extClassLoader.getParent();

        System.out.println("bootstrapClassLoader:" + bootstrapClassLoader);
        System.out.println("extClassLoader:" + extClassLoader);
        System.out.println("appClassLoader:" + appClassLoader);

        System.out.println();

        System.out.println("bootstrapClassLoader加载的文件");
        URL[] urLs = Launcher.getBootstrapClassPath().getURLs();
        for(int i = 0;i < urLs.length;i++){
            System.out.println(urLs[i]);
        }

        System.out.println("extClassLoader加载的文件");
        System.out.println(System.getProperty("java.ext.dirs"));

        System.out.println("appClassLoader加载的文件");
        System.out.println(System.getProperty("java.class.path"));

    }
}
